package com.ruoyi.serverinfo.service;

import com.ruoyi.serverinfo.dao.TshockServerDao;
import com.ruoyi.serverinfo.entity.TshockServerInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TshockServerService {

    @Autowired
    private TshockServerDao serverDao;

    /**
     * 保存服务器信息
     */
    @Transactional
    public int saveServer(TshockServerInfo serverInfo) {
        return serverDao.save(serverInfo);
    }

    /**
     * 更新服务器信息
     */
    @Transactional
    public int updateServer(TshockServerInfo serverInfo) {
        return serverDao.update(serverInfo);
    }

    /**
     * 根据UUID删除服务器
     */
    @Transactional
    public int deleteServerByUuid(String uuid) {
        return serverDao.deleteByUuid(uuid);
    }

    /**
     * 根据UUID查询服务器
     */
    public TshockServerInfo getServerByUuid(String uuid) {
        return serverDao.findByUuid(uuid);
    }

    /**
     * 根据openid查询用户的服务器列表
     */
    public List<TshockServerInfo> getServersByOpenid(String openid) {
        return serverDao.findByOpenid(openid);
    }

    /**
     * 获取所有服务器列表
     */
    public List<TshockServerInfo> getAllServers() {
        return serverDao.findAll();
    }
}
    